package com.github.shiqiyue.learn.guava;

import com.google.common.primitives.Ints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/***
 * Ints测试
 * @author wenyao.wu
 * @date 2018/7/3
 */
public class IntsTest {

    private static final Logger logger = LoggerFactory.getLogger(IntsTest.class);

    public static void main(String[] args) {
        int[] intArray = {1, 2, 3, 4, 5, 6, 7, 8, 9};

        //convert array of primitives to array of objects
        List<Integer> objectArray = Ints.asList(intArray);
        logger.info(objectArray.toString());

        //convert array of objects to array of primitives
        logger.info("{}", intArray);
        //check if element is present in the list of primitives or not
        logger.info("5 is in list? {}", Ints.contains(intArray, 5));

        //Returns the minimum
        logger.info("Min: {}", Ints.min(intArray));

        //Returns the maximum
        logger.info("Max: {}", Ints.max(intArray));

        //get the byte array from an integer
        byte[] byteArray = Ints.toByteArray(20000);
        logger.info("{}", byteArray);
    }
}
